package com.qf;

import com.qf.conf.LoadBalancerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient

//启用hystrix服务保护功能
@EnableCircuitBreaker
//配置我们的负载均衡策略
@RibbonClient(name = "QF-ORDER",configuration = LoadBalancerConfig.class)

//开启Feign客户端功能支持
@EnableFeignClients
public class QFUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(QFUserApplication.class, args);
    }

    @Bean
    @LoadBalanced //将Ribbon整合到RestTemplate中。会向RestTemplate中设置一个LoaderBalancerInterceptor
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
